<template>
  <div class="divBox relative">
    <el-card class="box-card">
      
      
      <div class="container mt-1">
        <el-form ref="form" :model="form" label-width="180px">
          <el-form-item label="企业微信ID" prop="corpid">
            <el-input v-model="form.qy_appid" size="small" placeholder="请输入企业微信的企业ID"  show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="企业微信秘钥" prop="secret">
            <el-input v-model="form.qy_secret" size="small"  placeholder="请输入企业微信的应用秘钥"></el-input>
          </el-form-item>
		  <el-form-item label="令牌token" prop="secret">
		    <el-input v-model="form.qy_token" size="small"  placeholder="请输入企业微信后台设置的Token"></el-input>
		  </el-form-item>
		  <el-form-item label="秘钥encoding_aes_key" prop="secret">
		    <el-input v-model="form.encoding_aes_key" size="small"  placeholder="请输入企业微信后台设置的encoding_aes_key"></el-input>
		  </el-form-item>
		  <el-form-item label="回调地址" prop="secret">
		    <el-input :value="$domain+notic_url" size="small" disabled placeholder="回调地址" ></el-input>
		  </el-form-item>
          <el-form-item label="小程序appid" prop="corpid">
            <el-input v-model="form.mini_appid" size="small" placeholder="请输入小程序的appid" show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="小程序秘钥" prop="secret">
            <el-input v-model="form.mini_secret" size="small" placeholder="请输入小程序的秘钥" ></el-input>
          </el-form-item>
		  
		  <el-form-item label="微信支付商户号" prop="secret">
		    <el-input v-model="form.mch_id" size="small" placeholder="请输入微信支付商户号" ></el-input>
		  </el-form-item>
		  <el-form-item label="证书序列号" prop="secret">
		    <el-input v-model="form.serial_no" size="small" placeholder="请输入微信支付证书序列号" ></el-input>
		  </el-form-item>
		  <el-form-item label="V3支付秘钥" prop="secret">
		    <el-input v-model="form.api_v3_key" size="small" placeholder="请输入微信支付V3支付秘钥" ></el-input>
		  </el-form-item>
		  <el-form-item label="V2支付秘钥" prop="secret">
		    <el-input v-model="form.api_v2_key" size="small" placeholder="请输入微信支付V2支付秘钥" ></el-input>
		  </el-form-item>
		  <!-- <el-form-item label="移动端链接" prop="secret">
		    <el-input :value="$domain+h5_url" size="small" disabled placeholder="回调地址" ></el-input>
		  </el-form-item> -->
          <el-form-item label="" prop="">
            <el-button type="primary" @click="submitForm" size="mini">保存设置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
		    id:'',
			qy_appid: '',
			qy_secret: '',
			mini_appid: '',
			mini_secret: '',
			mch_id:'',
			serial_no:"",
			api_v3_key:"",
			api_v2_key:'',
			qy_token:"",
			encoding_aes_key:""
      },
      notic_url:'',
	  h5_url:''
    }
  },
  mounted() {
    // 初始化时加载已有的企业微信配置
	let cid = sessionStorage.getItem('cid')
	this.notic_url = '/index/callback' + cid
	this.h5_url = '/h5/#/?cid=' + cid
    this.loadSettings();
  },
  methods: {
    // 加载企业微信设置
    loadSettings() {
      
	  this.$api.post('/sadmin/getSet',{}).then(res=>{
	  	  if(res.data){
			  for(let i in this.form){
				  this.form[i] = res.data[i]
			  }
		  }
	  })
    },
    
    // 提交表单
    submitForm() {
      this.$api.post('/sadmin/saveSet',this.form).then(res=>{
      	  this.$message.success('操作成功')
		  this.loadSettings()
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.divBox {
  
  .box-card {
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }
  .font-w-b {
    font-weight: bold;
  }
  .font-16 {
    font-size: 16px;
  }
  .main-color-dan {
    color: #409EFF;
  }
  .mt-1 {
    margin-top: 10px;
  }
}
</style>